package com.ruoyi.project.baoxiu.card.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.baoxiu.card.domain.OrderWarrantyCard;
import com.ruoyi.project.baoxiu.card.service.IOrderWarrantyCardService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 保修订单Controller
 * 
 * @author wyh
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/baoxiu/card")
public class OrderWarrantyCardController extends BaseController
{
    @Autowired
    private IOrderWarrantyCardService orderWarrantyCardService;

    /**
     * 查询保修订单列表
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderWarrantyCard orderWarrantyCard)
    {
        startPage();
        List<OrderWarrantyCard> list = orderWarrantyCardService.selectOrderWarrantyCardList(orderWarrantyCard);
        return getDataTable(list);
    }

    /**
     * 导出保修订单列表
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:export')")
    @Log(title = "保修订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderWarrantyCard orderWarrantyCard)
    {
        List<OrderWarrantyCard> list = orderWarrantyCardService.selectOrderWarrantyCardList(orderWarrantyCard);
        ExcelUtil<OrderWarrantyCard> util = new ExcelUtil<OrderWarrantyCard>(OrderWarrantyCard.class);
        util.exportExcel(response, list, "保修订单数据");
    }

    /**
     * 获取保修订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderWarrantyCardService.selectOrderWarrantyCardById(id));
    }

    /**
     * 新增保修订单
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:add')")
    @Log(title = "保修订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderWarrantyCard orderWarrantyCard)
    {
        return toAjax(orderWarrantyCardService.insertOrderWarrantyCard(orderWarrantyCard));
    }

    /**
     * 修改保修订单
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:edit')")
    @Log(title = "保修订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderWarrantyCard orderWarrantyCard)
    {
        return toAjax(orderWarrantyCardService.updateOrderWarrantyCard(orderWarrantyCard));
    }

    /**
     * 删除保修订单
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:card:remove')")
    @Log(title = "保修订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderWarrantyCardService.deleteOrderWarrantyCardByIds(ids));
    }
}
